<script lang="ts" setup>
//import formPage from "./formPage.vue";
import { getPatientInfo } from "../service";
import { IResponseData } from "@/@types/utils.request";

const props = defineProps({
	modelValue: {
		type: Boolean,
		default: false,
	},
	orderNo: {
		type: String,
		default: "",
	},
});

const emit = defineEmits<{
	(e: "update:modelValue", value: boolean): void;
}>();
const visible = computed({
	get() {
		return props.modelValue;
	},
	set(val) {
		emit("update:modelValue", !!val);
	},
});
const orderNo = computed(() => props.orderNo);

const getFetch = async () => {
	try {
		console.log("getFetch", orderNo.value);
		const response: IResponseData<any> = await getPatientInfo({
			orderNo: orderNo.value,
		} as any);
		const { code, msg, data } = response;
		if (code === 0) {
			const orderPics = data.orderPics.map((item: { picPath: string }) => item.picPath);
			viewData.value = { ...data, orderPics };
		} else {
			ElMessage({
				message: msg,
				type: "error",
			});
		}
	} catch (error: any) {
		console.log(error);
	}
};

const viewData = ref({
	id: 1,
	birthday: "1987-10-24",
	idCard: "330127198710243719",
	isDelete: 0,
	sex: 1,
	weight: 55,
	height: 170,
	updateTime: 1673228208000,
	relation: 0,
	orderPics: [],
	name: "张三",
	phone: "13812345678",
	address: "北京市海淀区",
	illnessRemark: "",
	appointmentTime: "",
});
</script>
<template>
	<el-dialog v-model="visible" title="就诊人信息" width="520px" @open="getFetch">
		<el-form :model="viewData" label-width="auto">
			<el-form-item label="姓名：">{{ viewData.name }}</el-form-item>
			<el-form-item label="用户ID：">{{ viewData.id }}</el-form-item>
			<el-form-item label="联系方式：">{{ viewData.phone }}</el-form-item>
			<el-form-item label="性别：">{{ viewData.sex === 1 ? "男" : "女" }}</el-form-item>
			<el-form-item label="出生日期：">{{ viewData.birthday }}</el-form-item>
			<el-form-item label="订单预约时间：">{{ viewData.appointmentTime }}</el-form-item>
			<el-form-item label="身高：">{{ viewData.height }}kg</el-form-item>
			<el-form-item label="体重：">{{ viewData.weight }}kg</el-form-item>
			<el-form-item label="身份证号：">{{ viewData.idCard }}</el-form-item>
			<el-form-item label="家庭住址：">{{ viewData.address }}</el-form-item>
			<el-form-item label="病情信息：">{{ viewData.illnessRemark }}</el-form-item>
			<el-form-item label="照片：">
				<el-image
					v-for="(item, index) in viewData.orderPics"
					:key="index"
					style="width: 100px; height: 100px; margin: 6px"
					:src="item"
					:zoom-rate="1.2"
					:max-scale="7"
					:min-scale="0.2"
					:preview-src-list="viewData.orderPics"
					:initial-index="4"
					fit="cover"
				/>
			</el-form-item>
		</el-form>
	</el-dialog>
</template>
